/** @file caMaps.h
 * ConArtist maps from URI to content are stored in "stores", one per
 * generator.
 */

/*
 * Licensed to the ConArtist Development Team (CADT).
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * The CADT licenses this file to you under the Apache License, 
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CAMAPS_H
#define CAMAPS_H

#include <apr_pools.h>
#include <apr_tables.h>
#include <apr_thread_rwlock.h>
#include <apr_hash.h>

#include "caPipeline.h"
#include "caGenerator.h"

/** @defgroup MAPS ConArtist Mappings
 * @{
 */

/** Each map store contains any number of caURIMap structures. */
struct caMapStore {
    apr_pool_t *pool;            /**< We'll use a subpool for the store */
    apr_thread_rwlock_t *rwLock; /**< Read/Write lock for access */

    apr_hash_t *uriHash;         /**< Hash of maps with URI's */
    apr_hash_t *mapHash;         /**< Hash of maps with no URI */
};

/** Once created each generator needs a number of mappings that control
 * how we go from a requested URI to an output file.
 *
 * If we have no pipeline defined but we have an output filename specified,
 * then if the output filename exists it will be served. If there is a
 * pipeline defined then the output filename will be used as the initial
 * input data for the pipeline.
 *
 * If the content filename is set this file will be served if it exists.
 */
struct caURIMap {
    /* From */
    /* Match */
    char *path;                  /**< Path we apply to */
    apr_size_t pLen;             /**< Path length */

    char *filename;              /**< Filename or fnmatch pattern that
                                  * is used on everything following the
                                  * path to detrmine a match
                                  */
    /* URI */
    char *URI;                   /**< The full URL this structure is
                                  * used for. NULL if wildcards in use.
                                  */
    /* Dependancies */
    apr_hash_t *deps;            /**< Filenames that this mapping depends
                                  * on. These must exist before this
                                  * mapping is created.
                                  */
    /* Output */
    char *output;                /**< Output filename to use */
    struct pipelineInstance *pi; /**< Pipeline to process data via */

    /* Content */
    int flags;                   /**< OR'd CAM_ constants */
    char *generatedFn;           /**< Location of generated file */
    apr_size_t fLen;             /**< Size of file stored on disk */
};

/** @fn apr_status_t caMapStoreCreate(struct caMapStore **store,
                                      apr_pool_t *parentPool);
 * Create a new map store. The store structure will be allocated from
 * the pool supplied, but will create a subpool for all internal
 * allocations.
 * @param store Pointer to the created caMapStore structure
 * @param parentPool The pool to create subpool from
 */
apr_status_t caMapStoreCreate(struct caMapStore **, apr_pool_t *);

/** @} */

#endif /* CAMAPS_H */
